/*
 * Copyright © Yan Zhenjie. All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sql.azarias.activity;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;

import com.sql.azarias.http.AbstractRequestNew;
import com.sql.azarias.http.CallServer;
import com.sql.azarias.http.HttpListener;
import com.yanzhenjie.nohttp.rest.RequestQueue;

/**
 * Created by SQLong on 2017/2/7.
 */
public class BaseActivity extends AppCompatActivity {
    /**
     * 用来标记取消。
     */
    private Object object = new Object();

    protected <T> void request(Context activity, AbstractRequestNew<T> request, HttpListener<T> httpListener ) {
        CallServer.getInstance().add(activity,0, request, httpListener);
    }

    protected <T> void request( Context activity ,int what,AbstractRequestNew<T> request, HttpListener<T> httpListener) {
        request.setCancelSign(object);
        CallServer.getInstance().add(activity,what, request, httpListener);
    }

    @Override
    protected void onDestroy() {
        // 和声明周期绑定，退出时取消这个队列中的所有请求，当然可以在你想取消的时候取消也可以，不一定和声明周期绑定。
        CallServer.getInstance().cancelBySign(object);

        super.onDestroy();
    }
}
